package com.yuwubao.hz_International.services.impl;

import com.yuwubao.hz_International.entities.WelfareConfigEntity;
import com.yuwubao.hz_International.entities.repository.WelfareConfigRepository;
import com.yuwubao.hz_International.services.WelfareConfigService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by yangyu on 2018/1/25.
 */
@Service
public class WelfareConfigServiceImpl implements WelfareConfigService {

    @Autowired
    private WelfareConfigRepository welfareConfigRepository;

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<WelfareConfigEntity> findAll() {
        return welfareConfigRepository.findAll();
    }

    @Override
    public WelfareConfigEntity save(WelfareConfigEntity welfareConfig) {
        return welfareConfigRepository.save(welfareConfig);
    }

    @Override
    public WelfareConfigEntity update(WelfareConfigEntity welfareConfig) {
        WelfareConfigEntity welfareConfigEntity = welfareConfigRepository.findOne(welfareConfig.getId());
        if (welfareConfigEntity != null) {
            ModelMapper model = new ModelMapper();
            WelfareConfigEntity entity = model.map(welfareConfig, WelfareConfigEntity.class);
            return welfareConfigRepository.save(entity);
        }
        return null;
    }
}
